const db = require("./db");

function ProPic(pic) {
    this.id = pic.id;
    this.picName = pic.picName;
    this.picAddr = pic.picAddr;
    this.productId = pic.productId;
}
ProPic.queryPic = (proId, callback) => {
    let selectSql = 'SELECT * FROM product_picture WHERE productId in(' + proId + ')';
    console.log(selectSql);
    db.query(selectSql, (err, result) => {
        if (err) {
            return callback(err);
        }
        callback(err, result);
    });
};
ProPic.addPic = (pic, callback) => {
    let selectSql = 'insert into product_picture (id, picName, productId, picAddr)  values (null, ?, ?, ?)';
    db.query(selectSql, [pic.picName, pic.productId, pic.picAddr], (err, result) => {
        if (err) return callback(err);
        callback(err, result);
    })
}
ProPic.delPic = (proId, callback) => {
    let selectSql = 'DELETE FROM product_picture WHERE  productId =?';
    db.query(selectSql,[proId],function (err, result) {
        if (err) return callback(err);
        callback(err, result);
    });
  };

module.exports = ProPic;